package com.zxjbyte.yiyi.framework.jackson.module;

import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.PackageVersion;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
import com.zxjbyte.yiyi.framework.common.constant.Constant;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * java 8 时间默认序列化
 * @Author zhangxingjia
 * @Date 2023/3/1 17:40
 * @Version: 1.0
 */
public class YiyiJavaTimeModule extends SimpleModule {

    public static final YiyiJavaTimeModule INSTANCE = new YiyiJavaTimeModule();

    public YiyiJavaTimeModule() {
        super(PackageVersion.VERSION);
        this.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(Constant.DATETIME_FORMAT));
        this.addDeserializer(LocalDate.class, new LocalDateDeserializer(Constant.DATE_FORMAT));
        this.addDeserializer(LocalTime.class, new LocalTimeDeserializer(Constant.TIME_FORMAT));
        this.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(Constant.DATETIME_FORMAT));
        this.addSerializer(LocalDate.class, new LocalDateSerializer(Constant.DATE_FORMAT));
        this.addSerializer(LocalTime.class, new LocalTimeSerializer(Constant.TIME_FORMAT));
    }
}
